package com.yang.doctorrecruitment.action;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.JobDAO;
import com.yang.doctorrecruitment.dto.ReleaseJob;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

public class SearchJobAction extends ActionSupport {
    private JSONArray job;
   public String SearchJob(){
       ActionContext ac=ActionContext.getContext();
       HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
       String seachID=request.getParameter("select");
       String seachContent=request.getParameter("content");
       if(seachContent==null){
           return ERROR;
       }else{
           //执行搜索
           if(seachID.equals("1")){
               //执行关键字搜索
               List<ReleaseJob> jobs= JobDAO.searchByStatic(seachContent);
               JSONArray array= JSONArray.parseArray(JSON.toJSONString(jobs));
               job=array;
               return SUCCESS;
           }else if(seachID.equals("2")){
               List<ReleaseJob> jobs= JobDAO.searchByJobAddress(seachContent);
               JSONArray array= JSONArray.parseArray(JSON.toJSONString(jobs));
               job=array;
               return SUCCESS;
               //执行工作地点搜索
           }else if(seachID.equals("3")){
               //执行工作名称搜索
               List<ReleaseJob> jobs= JobDAO.searchByJobName(seachContent);
               JSONArray array= JSONArray.parseArray(JSON.toJSONString(jobs));
               job=array;
               return SUCCESS;
           }else{
               return SUCCESS;
           }

       }


   }

    public JSONArray getJob() {
        return job;
    }

    public void setJob(JSONArray job) {
        this.job = job;
    }
}
